package com.tuanzi.loan.web.lazy;

import com.tuanzi.loan.core.lazy.BaseLazyDataModel;
import com.tuanzi.loan.core.vo.IdentityResponse;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.web.bean.CurrentUserBean;
import org.springframework.data.domain.Page;

/**
 * @Auther: 钟富澎
 * @Date: 2019/9/5
 * @Description: 基于 {@link BaseLazyDataModel}实现且带有“会话”性质的 Model，用于在查询时保存查询参数。
 */
public abstract class LazyDataSessionModel<K, T extends IdentityResponse> extends BaseLazyDataModel<K, T> {

    private CurrentUserBean session;

    public LazyDataSessionModel(K k, CurrentUserBean session) {
        super(k);
        this.session = session;
    }

    public K getSearchRequest() {
      return searchRequest;
    }

    @Override
    protected Page<T> doLoad(PageSearcher<K> pageSearcher) {
        Page<T> result = doLoad0(pageSearcher);
        session.addSearchParam(this);
        return result;
    }

    protected abstract Page<T> doLoad0(PageSearcher<K> pageSearcher);
}
